package com.github.shuaidd.rest.editor;

import com.github.shuaidd.model.execption.NotFoundException;
import org.activiti.app.domain.editor.Model;
import org.activiti.app.domain.editor.ModelInformation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("app")
public class ModelRelationResource extends AbstractModelResource {

    @RequestMapping(value = "/rest/models/{modelId}/parent-relations", method = RequestMethod.GET, produces = "application/json")
    public List<ModelInformation> getModelRelations(@PathVariable String modelId) {
        Model model = modelService.getModel(modelId);
        if (model == null) {
            throw new NotFoundException();
        }
        return modelService.findParentModels(modelId);
    }

}
